package com.restaurant.ressys.controller;


import com.restaurant.ressys.dao.NewsMapper;
import com.restaurant.ressys.entity.News;
import com.restaurant.ressys.service.NewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2022-02-28
 */
@RestController
@RequestMapping("/news")
public class NewsController {
    @Resource
    private NewsService newsService;
    @GetMapping("/getAll")
    public List<News> getAll(){
        return newsService.list();
    }
    @PostMapping("/add")
    public void add(@RequestBody News news){
       news.setCreatedate(LocalDate.now());
        newsService.save(news);
    }
    @DeleteMapping("/del/{id}")
    public void delNews(@PathVariable Integer id){
        newsService.removeById(id);
    }
}

